home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-08-26 | 4.0 KB | 98 lines | [TEXT/MPS ] |
- /*
- When the AppleEvent Registry and Inside Mac volume VI were first released,
- the documented type for error strings and other stuff was typeChar ('TEXT').
- Well, as we went along designing things like AppleScript, we realized
- that typeChar was not suitable for a lot of developers and countries.
- Multi-byte scripts couldn't use typeChar and maintain all the information
- they needed to, and other Bad Things were implied by typeChar.
-
- So, the Winter '92 AE Registry introduced a new type, typeIntlText, defined as
- (quoting from the AERegistry)...
- A typeIntlText descriptor record contains identifiers for the language and script
- system of text followed by the text itself.
- Description The dataHandle field of a typeIntlText descriptor record contains the
- following:
- a 2-byte script code that identifies the script system of the text
- a 2-byte language code that identifies the language of the text
- the characters in the text (a series of either 1- or 2-byte characters
- ; the script system determines whether the characters are 1 or 2 bytes in length)
-
- That's great and wonderful, but heck, a lot of you (and Me) had already
- written code that supplied typeChar for errors and other things that should now be
- typeIntlText (note for you programmers: Don't worry, code really is coming soon).
-
- What's a Coder to Do?
- You can fix your stuff so you supply typeIntlText, but what about all the
- other stuff out there that's giving you back typeChar when you want typeIntlText????
-
- A Coercion Routine!
-
- And here it is. This coercion routine coerces from typeChar to typeIntlText.
- Put this in your code, then when someone sends you typeChar when you've asked for
- typeIntlText, this coercion routine will give you what you asked for seamlessly,
- you won't even know the coercion happened.
-
- EnJoy
-
- C.K. Haun
- Apple Developer Tech Support
- Aug '92.
-
- */
-
- /* the coercion. See after this code chunk for code for installing it */
-
- pascal OSErr CoerceTEXTToIntl(DescType origData, Ptr inPtr, Size theSize, DescType toType, long refCon, AEDesc *result)
- {
- OSErr myErr = noErr;
- Handle newDataHandle;
- Ptr scratchPtr;
- /* first see if the stuff we're coercing is correct. This _should_ never
- really be necessary, since the AEM wouldn't have dispatched to us if it wasn't
- right, but Hey, I'm paranoid. */
- if(origData == typeText && toType == typeIntlText){
- /* the data handle for typeIntlText contains
- 2 byte script code
- 2 byte language code
- the characters.
- So, we'll do something like this....
- */
- /* Get a handle to convert the text to intltext */
- newDataHandle = NewHandle(theSize + 4); /* TEXT size plus those 2 new shorts */
- if(newDataHandle && MemError() == noErr){
- /* got the handle size I needed */
- scratchPtr = *newDataHandle;
- /* I'm going to default the script and language values to system, since I don't know where */
- /* this text is coming from, so I can't assume application script settings */
- /* This means I will be wrong some times, but since this is a stopgap anyway. */
- /* I'll live with it */
- *((short *)scratchPtr = iuCurrentScript;
- scratchPtr = scratchPtr + 2; /* two bytes further */
- *((short *)scratchPtr = iuCurrentCurLang;
- /* now move the actual bytes */
- HLock(newDataHandle);
- scratchPtr = scratchPtr + 2; /* two bytes further */
- BlockMove(inPtr,scratchPtr,theSize);
-
- /* put this in the resulting AEDesc for the coercion */
- myErr = AECreateDesc(typeIntlText,*newDataHandle,GetHandleSize(newDataHandle),result);
- /* we've put the data in the desc, get rid of my intermediate handle now */
- DisposHandle(newDataHandle);
- /* and exit, the only error from this bit will be the AECreateDesc error and we can propigate */
- /* that along */
- }
-
- } else {
- /* bad data passed */
- myErr = errAECoercionFail;
- }
- return(myErr);
- }
-
- /* see if there already is one */
- installErr = AEGetCoercionHandler(typeChar, typeIntlText, &oldHandler, &oldRefCon, &typeIsDesc, true);
- /* if there already was one, I don't install mine */
- if(installErr == noErr ){
- installErr = AEInstallCoercionHandler(typeChar, typeIntlText, (ProcPtr)CoerceTEXTToIntl, nil, false, true);
-
- }